package com.cn.cs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import static java.lang.Class.forName;
//选择
public class work3 {
    public static void main(String[] args) {
        try {
            forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql1", "root", "root");
            //获取操作数据库的对象
            PreparedStatement pst = con.prepareStatement("SELECT * from student ");
            //执行sql获取结果数据
            ResultSet rs = pst.executeQuery();
            //遍历结果集
            while (rs.next()) {
                System.out.println("\t学生id:" + rs.getString("id") + "\t班级:" + rs.getInt("class") + "\t姓名:" + rs.getString("name"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
